//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
import Member_coupon_hisFQ from '../../views/mall/Member_coupon_hisFQ.vue'
let extension = {
  components: {//动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: '',//{ template: "<div>扩展组xx件</div>" },
    gridBody: Member_coupon_hisFQ,
    gridFooter: '',
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: '',
    modelBody: '',
    modelFooter: ''
  },
  buttons: {
    view: [
      {
        name: "分配",
        icon: 'md-add',
        value: 'LQ',
        class: '',
        type: 'error',
        index: 1,//显示的位置
        onClick: function () {
          this.$refs.gridBody.model9 = true;
          this.$refs.gridBody.MebcouponMakeGetPageData()
          this.$refs.gridBody.getMebCouponhis(undefined)
        }
      },
    ], box: [], detail: []
  },//扩展的按钮
  methods: {//事件扩展
    getFormOption (field) {
      let option;
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == field) {
            option = item;
          }
        })
      })
      return option;
    },
    getSearchFormOption (field) {
      let option;
      this.searchFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == field) {
            option = item;
          }
        })
      })
      return option;
    },
    onInit () {
      this.$store.getters.data().viewPageTest = this
      this.columns.push({
        title: '操作',
        fixed: 'right',
        width: 200,
        render: (h, { row, column, index }) => {
          return [h(
            'el-button', {
            props: {
              type: 'text', size: 'mini',
              disabled: (row.memberid != "" || row.use_status == 5)
            },
            on: {
              click: () => {
                this.$refs.gridBody.model3 = true;
                this.$refs.gridBody.FJGR = row
                this.$nextTick(() => {
                  this.$refs.gridBody.$refs.myform3.reset()
                  this.$refs.gridBody.HYZHSTATUS = false
                })
              }
            }
          }, '发券'),
          h(
            'el-button', {
            props: {
              type: 'text', size: 'mini',
              disabled: (row.use_status == 5 || row.use_status == 2)
            },
            on: {
              click: () => {
                this.$refs.gridBody.model8 = true;
                this.$refs.gridBody.SGHX = row
                this.$nextTick(() => {
                  this.$refs.gridBody.formRules8 = [
                    [
                      {
                        title: "备注",
                        field: "remark",
                        type: "text",
                        min: row.validatedate,
                        required: true,
                      },
                    ],
                  ],
                    this.$refs.gridBody.formFields8.remark = ''
                })
              }
            }
          }, "作废"),
          h('el-button',
            {
              props: {
                type: 'text', size: 'mini',
                disabled: (row.memberid == "" || row.use_status == 5)
              },
              on: {
                click: (e) => {
                  this.$refs.gridBody.model6 = true;
                  this.$refs.gridBody.FJGR = row
                  this.$nextTick(() => {
                    this.$refs.gridBody.formRules6 = [
                      [
                        {
                          title: "延期时间",
                          field: "use_endtime",
                          type: "datetime",
                          min: row.validatedate,
                          required: true,
                        },
                      ],
                    ],
                      this.$refs.gridBody.formFields6.use_endtime = ''
                  })
                },
              }
            }, '延期'),
          h('el-button',
            {
              props: {
                type: 'text', size: 'mini',
                disabled: (row.use_status == 2 || row.use_status == 5)
              },
              on: {
                click: (e) => {
                  this.$refs.gridBody.model7 = true;
                  this.$refs.gridBody.SGHX = row
                  this.$nextTick(() => {
                    this.$refs.gridBody.formRules7 = [
                      [
                        {
                          title: "备注",
                          field: "remark",
                          type: "text",
                          min: row.validatedate,
                          required: true,
                        },
                      ],
                    ],
                      this.$refs.gridBody.formFields7.remark = ''
                  })
                },
              }
            }, '手工核销')]
        }
      })
      let QUANBAO = this.getSearchFormOption('member_coupon_tag_id')
      QUANBAO.data = []
      let params = {
        order: "desc",
        page: 1,
        rows: 30,
        sort: "id",
        wheres: "[{\"name\":\"coupon_type\",\"value\":\"1\",\"displayType\":\"text\"}]"
      }
      this.http.post("/api/MebcouponMake/getPageData", params).then(res => {
        res.rows.forEach(i => {
          let obj = {
            key: i.coupon_makeid,
            value: i.coupon_name
          }
          QUANBAO.data.push(obj)
        })
      })
      let po = {
        order: "desc",
        page: 1,
        rows: 9999999,
        sort: "id",
        wheres: "[]"
      };
      this.http.post("/api/Users/GetSysUser", po).then(res => {
        res.rows.forEach(i => {
          let obj = {
            key: i.user_Id,
            label: i.userTrueName
          };
          this.$refs.gridBody.formRules4[0][0].data.push(obj);
        });
      });
    },
    rowClick ({ row, column, event }) { //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
    issueCoupons () {
      this.$refs.gridBody.model = true;
      this.$nextTick(() => {
        this.$refs.gridBody.$refs.myform.reset()
        this.$refs.gridBody.$refs.myform2.reset()
      })
      this.$refs.gridBody.MebcouponMakeGetPageData()
      this.$refs.gridBody.tableData2 = []
      this.$refs.gridBody.HYStatus = false
    }
  }
};
export default extension;
